﻿using System;
using System.Data;



 public   class TransactionsBO
 {
		public TransactionsBO(string _accountId, decimal _amount, string _payeeAccountId)
		{
			AccountId=_accountId;
			PayerAccountId=_accountId;
			PayeeAccountId = _payeeAccountId;
			Amount = _amount;
			PayerAmount = GetPayerAmount();
			PayeeAmount = GetPayeeAmount();
			TransactionDate = DateTime.Now;
			
		}

        private string _payerAccountId;
        private string _payeeAccountId;
        private string _accountId;
        private decimal _payerAmount;
	    private decimal _payeeAmount;
        private decimal _amount;
		private DateTime m_TransactionDate;
	 
        public decimal Amount
        {
            get { return _amount; }
			private  set { _amount = value; }
        }

        public decimal PayeeAmount
        {
            get { return _payeeAmount; }
			private set { _payeeAmount = GetPayeeAmount(); }
        }

        public decimal PayerAmount
        {
            get { return _payerAmount; }
			private set { _payerAmount = GetPayerAmount(); }
        }
        public string AccountId
        {
            get { return _accountId; }
            private set { _accountId = value; }
        }
		public string PayeeAccountId
        {
            get { return _payeeAccountId; }
			private set { _payeeAccountId = value; }
        }

        public string PayerAccountId
        {
            get { return _payerAccountId; }
			private set { _payerAccountId = value; }
        }
        

        public DateTime TransactionDate
        {
            get { return m_TransactionDate; }
			private set { m_TransactionDate = value; }
        }

		TransactionsDAL _TransactionsDal = new TransactionsDAL();
	 


      public int InsertTransaction()
      {
         
          try
          {
		  PayerAmount = GetPayerAmount();
		  PayeeAmount = GetPayeeAmount();
		
		  if (PayerAmount <= Amount)
			  {
			  throw new Exception("Insufficient Balance");
			  }
		  else
			  {
			  return _TransactionsDal.AddTransaction(this);
			  }
          }
          catch (Exception ex)
          {
              throw ex;
          }
      }

  

      public DataTable AccountFillDropDown()
      {
		  try
          {
			 return _TransactionsDal.AccountFillDropDown();
          }

          catch
          {
              throw;
          }

      }
      public decimal GetPayeeAmount()
      {
          try
          {
		  return _TransactionsDal.GetPayeeAmount(this);
          }
          catch (Exception ex)
          {
              throw ex;
          }
         
      }

      public decimal GetPayerAmount()
      {
          try
          {
		  return _TransactionsDal.GetPayerAmount(this);
          }
          catch (Exception ex)
          {
              throw ex;
          }
        
      }

  }

